package com.hqd.ch03.v22.aop.framework.aspectj;

import com.hqd.ch03.v22.aop.ProxyMethodInvocation;
import com.hqd.ch03.v22.aopalliance.intercept.MethodInterceptor;
import com.hqd.ch03.v22.aopalliance.intercept.MethodInvocation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.weaver.tools.JoinPointMatch;

import java.lang.reflect.Method;

public class AspectJAroundAdvice extends AbstractAspectJAdvice implements MethodInterceptor {
    public AspectJAroundAdvice(AspectJExpressionPointcut pointcut, Method aspectJAdviceMethod, Object aspect) {
        super(pointcut, aspectJAdviceMethod, aspect);
    }

    @Override
    public boolean isBeforeAdvice() {
        return false;
    }

    @Override
    public boolean isAfterAdvice() {
        return false;
    }

    protected boolean supportsProceedingJoinPoint() {
        return true;
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
        ProceedingJoinPoint pjp = new MethodInvocationProceedingJoinPoint(pmi);
        JoinPointMatch jpm = getJoinPointMatch(pmi);
        return invokeAdviceMethod(mi.getMethod(), pjp, jpm, null, null, mi.getArguments());
    }
}
